﻿// TurnCoordinator - 转弯指示表
#include "TurnCoordinator.h"

void drawTC(double x0, double y0, double r,double turn_rate, double turn_rate2)
{
        double circle_x, circle_y, circle_r;//圆心和半径
        circle_x = x0, circle_y = y0, circle_r = r;
//        initgraph(1200, 800, INIT_RENDERMANUAL);//手动渲染，避免闪烁
        ege_enable_aa(true);//抗锯齿
//        setbkcolor(WHITE);//背景色白色


        g(circle_x, circle_y, circle_r);//图形
        key_msg msg;
        //{
        //    ege_point points2[] = {
        //            {circle_x - circle_r / 33 * 20,circle_y - circle_r / 60},
        //            {circle_x - circle_r / 33 * 20 + circle_r / 33 * 40,circle_y - circle_r / 60},
        //            {circle_x - circle_r / 33 * 20 + circle_r / 33 * 40,circle_y - circle_r / 60 + circle_r / 30},
        //            {circle_x ,circle_y - circle_r / 60 + circle_r * 2 / 30},
        //            {circle_x - circle_r / 33 * 20,circle_y - circle_r / 60 + circle_r / 30}
        //    };
        //    setfillcolor(EGERGB(192, 192, 192));
        //    ege_fillpoly(5, points2);//飞机机翼
        //    ege_fillcircle(circle_x, circle_y, circle_r / 11);
        //    ege_point points3[] = {
        //            {circle_x,circle_y - circle_r * 2 / 3 * 0.4 / 4.4},
        //            {circle_x - circle_r * 2 / 3 * 1.55 / 4.2,circle_y - circle_r * 2 / 3 * 0.5 / 4.4},
        //            {circle_x - circle_r * 2 / 3 * 1.55 / 4.2,circle_y - circle_r * 2 / 3 * 0.65 / 4.4},
        //            {circle_x - circle_r * 2 / 3 * 0.12 / 4.4,circle_y - circle_r * 2 / 3 * 0.65 / 4.4},
        //            {circle_x - circle_r * 2 / 3 * 0.12 / 4.4,circle_y - circle_r * 2 / 3 * 1.5 / 4.4},
        //            {circle_x + circle_r * 2 / 3 * 0.12 / 4.4,circle_y - circle_r * 2 / 3 * 1.5 / 4.4},
        //            {circle_x + circle_r * 2 / 3 * 0.12 / 4.4,circle_y - circle_r * 2 / 3 * 0.65 / 4.4},
        //            {circle_x + circle_r * 2 / 3 * 1.55 / 4.2,circle_y - circle_r * 2 / 3 * 0.65 / 4.4},
        //            {circle_x + circle_r * 2 / 3 * 1.55 / 4.2,circle_y - circle_r * 2 / 3 * 0.5 / 4.4}
        //    };
        //    ege_fillpoly(9, points3);//飞机上半部分 ，需要转动
        //}//飞机

        //{
        //    setfillcolor(EGEACOLOR(0xFF, 0x2B2B2B));
        //    double center_x = circle_x;
        //    double center_y = circle_y + circle_r * 2.7 / 27;
        //    double a = circle_r * 5 / 6;
        //    double b = circle_r * 8 / 27;
        //    double x_pos = center_x + a * cos(90 * M_PI / 180);
        //    double y_pos = center_y + b * sin(90 * M_PI / 180);
        //    int ellipse_w = circle_r * 10 / 54;//短半轴
        //    int ellipse_h = circle_r * 11 / 54;//长半轴
        //    ege_fillellipse(x_pos - ellipse_w / 2, y_pos - ellipse_h / 2, ellipse_w, ellipse_h);//小球
        //    float x3_1 = circle_x - circle_r * 1.11 / 5 * cos(55.714 * M_PI / 180); // ≈circle_x + circle_r * cos(65.714°)
        //    float y3_1 = circle_y + (circle_r / 2) * 1.12 * sin(65.714 * M_PI / 180); // ≈circle_y + (circle_r/2) * sin(65.714°)
        //    float x4_1 = circle_x + circle_r * 0.6 * cos(77.143 * M_PI / 180); // ≈circle_x + circle_r * cos(77.143°)
        //    float y4_1 = circle_y + (circle_r / 2) * 1.04 * sin(77.143 * M_PI / 180); // ≈circle_y + (circle_r/2) * sin(77.143°)
        //    float x3_2 = circle_x - (2 * circle_r / 6) * 1.23 * cos(72.571 * M_PI / 180); // ≈circle_x + (5*circle_r/6) * cos(72.571°)
        //    float y3_2 = circle_y + (8 * circle_r / 27) * sin(72.571 * M_PI / 180); // ≈circle_y + (8*circle_r/27) * sin(72.571°)
        //    float x4_2 = circle_x + (5 * circle_r / 6) * 1.05 * cos(81.428 * M_PI / 180); // ≈circle_x + (5*circle_r/6) * cos(91.428°)
        //    float y4_2 = circle_y + (8 * circle_r / 27) * 0.95 * sin(91.428 * M_PI / 180); // ≈circle_y + (8*circle_r/27) * sin(91.428°)
        //    //setcolor(EGEACOLOR(0xFF, 0x00292926));
        //    setcolor(BLACK);
        //    // 连接七分之三处
        //    ege_line(x3_1, y3_1, x3_2, y3_2);//黑线
        //    // 连接七分之四处
        //    ege_line(x4_1, y4_1, x4_2, y4_2);//黑线
        //    setlinewidth(4);//线条粗细
        //    setcolor(EGEARGB(40, 255, 255, 255));
        //    ege_arc(circle_x - circle_r * 5 / 6, circle_y - circle_r * 7.3 / 27, circle_r * 10 / 6, circle_r * 16 / 27, 22, 136);//白色反光
        //    ege_arc(circle_x - circle_r * 5 / 6, circle_y - circle_r * 6.8 / 27, circle_r * 10 / 6, circle_r * 16 / 27, 22, 136);//白色反光
        //}//小球

        if (turn_rate2  > 8) {
            turn_rate2 = 8;
        }
        if (turn_rate2 < -8) {
            turn_rate2 = -8;
        }
        turn_rate2 = (turn_rate2 * 3 + 90) * M_PI / 180;
        rightellipse(circle_x, circle_y, circle_r, turn_rate2);//小球
       /* turn_rate *= 0.6;*/

        if (turn_rate > -70 && turn_rate < 70) {
            turn_rate *= M_PI / 180;

            rightrevolve(circle_x, circle_y, circle_r, turn_rate);
        }
        else if (turn_rate <= -70)
        {
            turn_rate = -70;
            turn_rate *= M_PI / 180;

            rightrevolve(circle_x, circle_y, circle_r, turn_rate);
        }
        else
        {
            turn_rate = 70;
            turn_rate *= M_PI / 180;
            rightrevolve(circle_x, circle_y, circle_r, turn_rate);
        }

//        double angle1 = 90 * M_PI / 180;
////        for (; is_run(); delay_fps(60)) {
////            msg = getkey();
//            if (msg.key == key_left && msg.msg == key_msg_down) {
//
//                if (angle < -63 * M_PI / 180) {
//                    continue;
//                }
//                else {
//                    if (angle1 < 22 * M_PI / 180) {
//                        continue;
//                    }
//                    angle -= 0.015;                     // 角度递增（控制旋转速度）
//                    angle1 -= 0.005;
//                    cleardevice();
//                    if (angle <= -2 * M_PI) angle = 0;   // 防止角度溢出
//                    rightellipse(circle_x, circle_y, circle_r, angle1);
//                    rightrevolve(circle_x, circle_y, circle_r, angle);
//                }
//            }
//            else if (msg.key == key_right && msg.msg == key_msg_down) {
//
//                if (angle > 65 * M_PI / 180) {
//                    continue;
//                }
//                else {
//                    if (angle1 > 136 * M_PI / 180) {
//                        continue;
//                    }
//                    angle += 0.015;                     // 角度递增（控制旋转速度）
//                    angle1 += 0.005;
//                    cleardevice();
//                    if (angle <= -2 * M_PI) angle = 0;   // 防止角度溢出
//                    rightellipse(circle_x, circle_y, circle_r, angle1);
//                    rightrevolve(circle_x, circle_y, circle_r, angle);
//                }
//            }
//        }//飞机旋转



}

void g(double circle_x, double circle_y, double circle_r) {
//    setfillcolor(BLACK);//填充色为黑色,不透明
//    ege_fillrect(circle_x - circle_r * 8 / 6, circle_y - circle_r * 8 / 6, circle_r * 8 / 3, circle_r * 8 / 3);//边框
//    setfillcolor(EGERGB(100, 100, 100));//填充为灰色
//    ege_fillrect(circle_x - circle_r * 8 / 6 + circle_r / 60, circle_y - circle_r * 8 / 6 + circle_r / 60, circle_r * 8 / 3 - circle_r / 30, circle_r * 8 / 3 - circle_r / 30);//边框

    //{
    //    ege_point p = { circle_x - circle_r * 21 * 1 / 24 - circle_r / 17 ,circle_y - circle_r * 21 * 0.96 / 24 - circle_r / 17 };
    //    ege_setpattern_ellipsegradient(p, EGERGB(230, 230, 230), circle_x - circle_r * 21 / 24 - circle_r / 10, circle_y - circle_r * 21 / 24 - circle_r * 0.7 / 10, circle_r / 6, circle_r / 6, EGEACOLOR(0xFF, 0x000000));
    //    ege_fillrect(circle_x - circle_r * 21 / 24 - circle_r / 10, circle_y - circle_r * 21 / 24 - circle_r / 10, circle_r / 4, circle_r / 4);//左上角

    //    ege_point p2 = { circle_x + circle_r * 21 / 24 - circle_r / 17 ,circle_y - circle_r * 21 / 24 - circle_r / 17 };
    //    ege_setpattern_ellipsegradient(p2, EGERGB(230, 230, 230), circle_x + circle_r * 21 / 24 - circle_r / 10, circle_y - circle_r * 21 / 24 - circle_r / 10, circle_r / 6, circle_r / 6, EGEACOLOR(0xFF, 0x000000));
    //    ege_fillrect(circle_x + circle_r * 21 / 24 - circle_r / 10, circle_y - circle_r * 21 / 24 - circle_r / 10, circle_r / 4, circle_r / 4);//右上角

    //    ege_point p3 = { circle_x - circle_r * 21 / 24 - circle_r / 17 ,circle_y + circle_r * 21 / 24 - circle_r / 17 };
    //    ege_setpattern_ellipsegradient(p3, EGERGB(230, 230, 230), circle_x - circle_r * 21 / 24 - circle_r / 10, circle_y + circle_r * 21 / 24 - circle_r / 10, circle_r / 6, circle_r / 6, EGEACOLOR(0xFF, 0x000000));
    //    ege_fillrect(circle_x - circle_r * 21 / 24 - circle_r / 10, circle_y + circle_r * 21 / 24 - circle_r / 10, circle_r / 4, circle_r / 4);//左下角

    //    ege_point p4 = { circle_x + circle_r * 43 / 48 - circle_r / 17 ,circle_y + circle_r * 21 * 1.02 / 24 - circle_r / 17 };
    //    ege_setpattern_ellipsegradient(p4, EGERGB(230, 230, 230), circle_x + circle_r * 43 / 48 - circle_r / 10, circle_y + circle_r * 21 * 1.01 / 24 - circle_r / 10, circle_r / 6, circle_r / 6, EGEACOLOR(0xFF, 0x000000));
    //    ege_fillrect(circle_x + circle_r * 43 / 48 - circle_r / 10, circle_y + circle_r * 21 / 24 - circle_r / 10, circle_r / 4, circle_r / 4);//右下角
    //}//螺丝
    screwTC(circle_x, circle_y, circle_r);
    setfillcolor(EGERGB(0, 0, 0));//黑色,不透
    {
        setcolor(BLACK);//描边颜色
        setlinewidth(15);//线条粗细
        ege_circle(circle_x, circle_y, circle_r + circle_r / 10);//描边

        ege_point p5 = { circle_x - circle_r - circle_r / 10 + circle_r / 30 * 11 ,circle_y - circle_r - circle_r / 10 + circle_r / 30 * 11 };
        ege_setpattern_ellipsegradient(p5, EGERGB(160, 160, 160), circle_x - circle_r - circle_r / 10, circle_y - circle_r - circle_r / 10, 2 * (circle_r + circle_r / 10), 2 * (circle_r + circle_r / 10), EGEACOLOR(0xFF, 0x00161616));
        ege_fillrect(circle_x - circle_r - circle_r / 10, circle_y - circle_r - circle_r / 10, 2 * (circle_r + circle_r / 10), 2 * (circle_r + circle_r / 10));

    }//最外圈

    {
        setcolor(BLACK);//描边颜色
        setlinewidth(2);//线条粗细
        ege_circle(circle_x, circle_y, circle_r + circle_r * 3 / 150);//描边

        ege_point p6 = { circle_x - circle_r - circle_r / 300 * 2 + circle_r / 30 * 9 ,circle_y - circle_r - circle_r / 300 * 2 + circle_r / 30 * 9 };
        ege_setpattern_ellipsegradient(p6, EGERGB(200, 200, 200), circle_x - circle_r - circle_r / 300 * 6, circle_y - circle_r - circle_r / 300 * 6, 2 * (circle_r + circle_r / 300 * 6), 2 * (circle_r + circle_r / 300 * 6), EGEACOLOR(0xFF, 0x003A3A3C));
        ege_fillrect(circle_x - circle_r - circle_r / 300 * 6, circle_y - circle_r - circle_r / 300 * 6, 2 * (circle_r + circle_r / 300 * 6), 2 * (circle_r + circle_r / 300 * 6));

    }//第二圈

    {
        setcolor(BLACK);//描边颜色
        setlinewidth(14);//线条粗细
        ege_circle(circle_x, circle_y, circle_r - circle_r / 30);//描边

        ege_point p7 = { circle_x  ,circle_y };
        ege_setpattern_ellipsegradient(p7, EGERGB(70, 70, 70), circle_x - circle_r + circle_r / 30, circle_y - circle_r + circle_r / 30, 2 * (circle_r - circle_r / 30), 2 * (circle_r - circle_r / 30), EGEACOLOR(0xFF, 0x00292925));
        ege_fillrect(circle_x - circle_r + circle_r / 30, circle_y - circle_r + circle_r / 30, 2 * (circle_r - circle_r / 30), 2 * (circle_r - circle_r / 30));

    }//第三圈

    {
        setcolor(EGEACOLOR(0xFF, 0x00272723));
        setlinewidth(4);//线条粗细
        ege_circle(circle_x, circle_y, circle_r / 3 * 2);//描边

        ege_point p8 = { circle_x  ,circle_y };
        ege_setpattern_ellipsegradient(p8, EGEACOLOR(0xFF, 0x00292926), circle_x - circle_r / 3 * 2, circle_y - circle_r / 3 * 2, 2 * (circle_r / 3 * 2), 2 * (circle_r / 3 * 2), EGEACOLOR(0xFF, 0x00272723));
        ege_fillrect(circle_x - circle_r / 3 * 2, circle_y - circle_r / 3 * 2, 2 * (circle_r / 3 * 2), 2 * (circle_r / 3 * 2));

    }//第四圈

    {
        setfillcolor(EGERGB(192, 192, 192));//灰白色
        ege_fillrect(circle_x - circle_r / 6 * 5, circle_y - circle_r / 30, circle_r / 6, circle_r / 30 * 2);
        ege_fillrect(circle_x + circle_r / 3 * 2, circle_y - circle_r / 30, circle_r / 6, circle_r / 30 * 2);
        ege_point points[] = {
                {circle_x + (360 - 300) * circle_r / 300 - circle_r , circle_y + (480 - 300) * circle_r / 300 - circle_r / 3},
                {circle_x + (405 - 300) * circle_r / 300 - circle_r , circle_y + (460 - 300) * circle_r / 300 - circle_r / 3},
                {circle_x + (417 - 300) * circle_r / 300 - circle_r , circle_y + (480 - 300) * circle_r / 300 - circle_r / 3},
                {circle_x + (368 - 300) * circle_r / 300 - circle_r , circle_y + (500 - 300) * circle_r / 300 - circle_r / 3}
        };
        ege_fillpoly(4, points, NULL);
        ege_point points1[] = {
                {circle_x + (790 - 300) * circle_r / 300 - circle_r, circle_y + (460 - 300) * circle_r / 300 - circle_r / 3},
                {circle_x + (840 - 300) * circle_r / 300 - circle_r, circle_y + (480 - 300) * circle_r / 300 - circle_r / 3},
                {circle_x + (830 - 300) * circle_r / 300 - circle_r, circle_y + (500 - 300) * circle_r / 300 - circle_r / 3},
                {circle_x + (768 - 300) * circle_r / 300 - circle_r, circle_y + (476 - 300) * circle_r / 300 - circle_r / 3}
        };
        ege_fillpoly(4, points1, NULL);
    }//四个角
    settextjustify(LEFT_TEXT, TOP_TEXT);
    setcolor(EGERGB(170, 170, 170));
    setfont(circle_r / 300 * 46, circle_r / 300 * 16, "Arial");
    setbkmode(TRANSPARENT);//去除文字背景色
    outtextxy(circle_x - (circle_r * 3) / 5, circle_y + (circle_r * 4) / 9, "L");
    setfont(circle_r / 300 * 46, circle_r / 300 * 14, "Arial");
    outtextxy(circle_x + circle_r * 4 / 7, circle_y + (circle_r * 4) / 9, "R");
    setfont(circle_r / 300 * 34, circle_r / 300 * 12, "Arial");
    outtextxy(circle_x - circle_r * 8 / 100, circle_y - circle_r * 11 / 12, "D.C.");
    setfont(circle_r / 300 * 34, circle_r / 300 * 12, "Arial");
    outtextxy(circle_x - circle_r * 2.5 / 25, circle_y - circle_r * 4.95 / 6, "ELEC.");
    setfont(circle_r / 300 * 27, circle_r / 300 * 11, "Arial");
    outtextxy(circle_x - circle_r * 9.5 / 24, circle_y + circle_r * 6 / 40, "TURN COORDINATOR");
    setfont(circle_r / 300 * 32, circle_r / 300 * 18, "Arial");
    outtextxy(circle_x - circle_r / 6, circle_y + circle_r * 13 / 24, "2 MIN.");
    setfont(circle_r / 300 * 23, circle_r / 300 * 10, "Arial");
    outtextxy(circle_x - circle_r * 3 / 20, circle_y + circle_r * 23 / 32, "NO PITCH");
    outtextxy(circle_x - circle_r * 1.1 / 5, circle_y + circle_r * 76 / 96, "INFORMATION");
    {
        setcolor(EGERGB(119, 117, 101));
        setfillcolor(EGERGB(119, 117, 101));
        ege_arc(circle_x - circle_r, circle_y - circle_r / 2, 2 * circle_r, circle_r, 40, 100);//边界
        ege_arc(circle_x - circle_r * 5 / 6, circle_y - circle_r * 8 / 27, circle_r * 10 / 6, circle_r * 16 / 27, 16, 148);//边界
        setlinewidth(3);//线条粗细
        ege_circle(circle_x, circle_y, circle_r / 3 * 2);//闭合
        setfillcolor(EGERGB(119, 117, 101));
        floodfill(circle_x, circle_y + circle_r * 9 / 27, EGERGB(119, 117, 101));//填充滚动区域
        setcolor(EGEACOLOR(0xFF, 0x00242520));
        setlinewidth(5);//线条粗细
        ege_circle(circle_x, circle_y, circle_r / 3 * 2);//描边
        setcolor(BLACK);
    }//小球滚动范围
}

void rightrevolve(double circle_x, double circle_y, double circle_r, double angle) {
    setfillcolor(EGERGB(192, 192, 192));
    ege_point p2[] = {
            { -circle_r / 33 * 20, -circle_r / 60},
            { -circle_r / 33 * 20 + circle_r / 33 * 40, -circle_r / 60},
            { -circle_r / 33 * 20 + circle_r / 33 * 40, -circle_r / 60 + circle_r / 30},
            { 0, -circle_r / 60 + circle_r * 2 / 30},
            { -circle_r / 33 * 20, -circle_r / 60 + circle_r / 30}
    };
    ege_point p3[] = {
            {0, -circle_r * 2 / 3 * 0.4 / 4.4},
            {-circle_r * 2 / 3 * 1.55 / 4.2, -circle_r * 2 / 3 * 0.5 / 4.4},
            {-circle_r * 2 / 3 * 1.55 / 4.2, -circle_r * 2 / 3 * 0.65 / 4.4},
            {-circle_r * 2 / 3 * 0.12 / 4.4, -circle_r * 2 / 3 * 0.65 / 4.4},
            {-circle_r * 2 / 3 * 0.12 / 4.4, -circle_r * 2 / 3 * 1.5 / 4.4},
            {+circle_r * 2 / 3 * 0.12 / 4.4, -circle_r * 2 / 3 * 1.5 / 4.4},
            {+circle_r * 2 / 3 * 0.12 / 4.4, -circle_r * 2 / 3 * 0.65 / 4.4},
            {+circle_r * 2 / 3 * 1.55 / 4.2, -circle_r * 2 / 3 * 0.65 / 4.4},
            {+circle_r * 2 / 3 * 1.55 / 4.2, -circle_r * 2 / 3 * 0.5 / 4.4}
    };
    ege_point p2x[5] = { 0 };
    ege_point p3x[9] = { 0 };

    for (int i = 0; i < 5; i++) {
        double x = p2[i].x;
        double y = p2[i].y;
        p2x[i].x = circle_x + x * cos(angle) - y * sin(angle);
        p2x[i].y = circle_y + x * sin(angle) + y * cos(angle);
    }
    ege_fillpoly(5, p2x);
    for (int i = 0; i < 9; i++) {
        double x = p3[i].x;
        double y = p3[i].y;
        p3x[i].x = circle_x + x * cos(angle) - y * sin(angle);
        p3x[i].y = circle_y + x * sin(angle) + y * cos(angle);
    }
    ege_fillcircle(circle_x, circle_y, circle_r / 11);
    ege_fillpoly(9, p3x);

}//右转飞机

void rightellipse(double circle_x, double circle_y, double circle_r, double angle1) {
    //ege_arc(circle_x - circle_r * 5 / 6, circle_y - circle_r * 5.5 / 27, circle_r * 10 / 6, circle_r * 16 / 27, 22, 136);//运动路径
    //g(circle_x, circle_y, circle_r);
    setfillcolor(EGEACOLOR(255, 0x2B2B2B));
    double center_x = circle_x;//初始坐标
    double center_y = circle_y + circle_r * 2.7 / 27;//初始坐标
    double a = circle_r * 5 / 6;//短半轴
    double b = circle_r * 8 / 27;//长半轴
    double x_pos = center_x + a * cos(angle1);//旋转后坐标
    double y_pos = center_y + b * sin(angle1);//旋转后坐标
    int ellipse_w = circle_r * 10 / 54;//宽度
    int ellipse_h = circle_r * 11 / 54;//高度

    // 绘制移动的椭圆（左上角坐标模式）
    ege_fillellipse(
            x_pos - ellipse_w / 2,
            y_pos - ellipse_h / 2,
            ellipse_w,
            ellipse_h
    );
    float x3_1 = circle_x - circle_r * 1.11 / 5 * cos(55.714 * M_PI / 180); // ≈circle_x + circle_r * cos(65.714°)
    float y3_1 = circle_y + (circle_r / 2) * 1.12 * sin(65.714 * M_PI / 180); // ≈circle_y + (circle_r/2) * sin(65.714°)
    float x4_1 = circle_x + circle_r * 0.6 * cos(77.143 * M_PI / 180); // ≈circle_x + circle_r * cos(77.143°)
    float y4_1 = circle_y + (circle_r / 2) * 1.04 * sin(77.143 * M_PI / 180); // ≈circle_y + (circle_r/2) * sin(77.143°)
    float x3_2 = circle_x - (2 * circle_r / 6) * 1.23 * cos(72.571 * M_PI / 180); // ≈circle_x + (5*circle_r/6) * cos(72.571°)
    float y3_2 = circle_y + (8 * circle_r / 27) * sin(72.571 * M_PI / 180); // ≈circle_y + (8*circle_r/27) * sin(72.571°)
    float x4_2 = circle_x + (5 * circle_r / 6) * 1.05 * cos(81.428 * M_PI / 180); // ≈circle_x + (5*circle_r/6) * cos(91.428°)
    float y4_2 = circle_y + (8 * circle_r / 27) * 0.95 * sin(91.428 * M_PI / 180); // ≈circle_y + (8*circle_r/27) * sin(91.428°)
    
    setlinewidth(circle_r / 300 * 4);//线条粗细
    //setcolor(EGEACOLOR(255, 0x00292926));
    setcolor(BLACK);
    // 连接七分之三处
    ege_line(x3_1, y3_1, x3_2, y3_2);//黑线
    // 连接七分之四处
    ege_line(x4_1, y4_1, x4_2, y4_2);//黑线
    
    setcolor(EGEARGB(40, 255, 255, 255));
    ege_arc(circle_x - circle_r * 5 / 6, circle_y - circle_r * 7.3 / 27, circle_r * 10 / 6, circle_r * 16 / 27, 22, 136);//白色反光
    ege_arc(circle_x - circle_r * 5 / 6, circle_y - circle_r * 6.8 / 27, circle_r * 10 / 6, circle_r * 16 / 27, 22, 136);//白色反光
}
void screwTC(double centerX, double centerY, double dialRadius)
{
    // 使用float保证计算精度（根据需求可改为double）
    const float DIAL_RADIUS_F = (float)dialRadius;
    const float CENTER_X_F = (float)centerX;
    const float CENTER_Y_F = (float)centerY;

    // 参数化定义（精确到小数点后6位）
    const float SCREW_OFFSET = DIAL_RADIUS_F * 0.055555556f; // 1/18
    const float ELLIPSE_OFFSET_X = -DIAL_RADIUS_F * 0.111111111f; // -1/9
    const float ELLIPSE_OFFSET_Y = -DIAL_RADIUS_F * 0.166666667f; // -1/6
    const float ELLIPSE_SIZE = DIAL_RADIUS_F * 0.277777778f;  // 5/18
    const float RECT_OFFSET_X = DIAL_RADIUS_F * 0.222222222f;  // 2/9
    const float RECT_OFFSET_Y = DIAL_RADIUS_F * 0.333333333f;  // 1/3
    const float RECT_WIDTH = DIAL_RADIUS_F * 0.555555556f;   // 5/9
    const float RECT_HEIGHT = DIAL_RADIUS_F * 0.611111111f;  // 11/18
    const float CROSS_OFFSET1 = DIAL_RADIUS_F * 0.055555556f;  // 1/18
    const float CROSS_OFFSET2 = DIAL_RADIUS_F * 0.027777778f;  // 1/36
    const float LINE_WIDTH = DIAL_RADIUS_F * 0.016666667f;  // 1/60

    ege_enable_aa(TRUE);

    // 绘制函数（使用浮点坐标）
    auto draw_screw = [&](float cx, float cy) {
        // 精确到小数点后6位的渐变参数
        ege_setpattern_ellipsegradient(
            ege_point{ roundf(cx), roundf(cy) }, // 最终转整数
            EGEACOLOR(0xFF, BLACK),
            roundf(cx + ELLIPSE_OFFSET_X),
            roundf(cy + ELLIPSE_OFFSET_Y),
            roundf(ELLIPSE_SIZE),
            roundf(ELLIPSE_SIZE),
            EGEACOLOR(0, WHITE)
        );
        ege_fillrect(
            roundf(cx - RECT_OFFSET_X),
            roundf(cy - RECT_OFFSET_Y),
            roundf(RECT_WIDTH),
            roundf(RECT_HEIGHT)
        );

        // 灰色渐变层（精确尺寸调整）
        const float adjusted_size = ELLIPSE_SIZE - DIAL_RADIUS_F * 0.055555556f; // 替代原-10
        ege_setpattern_ellipsegradient(
            ege_point{
              roundf(cx - SCREW_OFFSET * 0.5f),
                roundf(cy - SCREW_OFFSET * 0.5f)
            },
            EGEACOLOR(0xFF, EGERGB(170, 170, 170)),
            roundf(cx + ELLIPSE_OFFSET_X),
            roundf(cy + ELLIPSE_OFFSET_Y),
            roundf(adjusted_size),
            roundf(adjusted_size),
            EGEACOLOR(0xFF, EGERGB(20, 20, 20))
        );
        ege_fillrect(
            roundf(cx - RECT_OFFSET_X),
            roundf(cy - RECT_OFFSET_Y),
            roundf(RECT_WIDTH),
            roundf(RECT_HEIGHT)
        );

        // 十字线（亚像素级精度）
        setcolor(EGERGB(30, 30, 30));
        setlinewidth(roundf(LINE_WIDTH));

        const float cross_y = cy - CROSS_OFFSET2 * 2.0f;
        ege_line(
            roundf(cx - CROSS_OFFSET1), roundf(cross_y),
            roundf(cx + CROSS_OFFSET1), roundf(cross_y)
        );

        const float cross_x = cx;
        const float cross_y_start = cy + CROSS_OFFSET2 / 4;
        const float cross_y_end = cy - CROSS_OFFSET2 * 4.0f;
        ege_line(
            roundf(cross_x), roundf(cross_y_start),
            roundf(cross_x), roundf(cross_y_end)
        );
        };

    // 计算四个螺丝中心坐标（浮点运算）
    const float screw_radius = DIAL_RADIUS_F - SCREW_OFFSET;

    // 左上
    draw_screw(
        CENTER_X_F - screw_radius,
        CENTER_Y_F - DIAL_RADIUS_F
    );

    // 右上
    draw_screw(
        CENTER_X_F + screw_radius,
        CENTER_Y_F - DIAL_RADIUS_F
    );

    // 右下
    draw_screw(
        CENTER_X_F + screw_radius,
        CENTER_Y_F + DIAL_RADIUS_F
    );

    // 左下（新增）
    draw_screw(
        CENTER_X_F - screw_radius,
        CENTER_Y_F + DIAL_RADIUS_F
    );
}